package com.ozo.cloud.common.log;

import com.ozo.cloud.api.system.feign.SysOperateLogFeignClient;
import com.ozo.cloud.common.log.aspect.OperateLogAspect;
import com.ozo.cloud.common.log.event.OperateLogListener;
import com.ozo.cloud.common.log.properties.LogProperties;
import net.dreamlu.mica.ip2region.config.Ip2regionConfiguration;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;

/**
 * 操作日志自动配置类
 *
 * @author qiangesoft
 * @date 2024-04-11
 */
@EnableAsync
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties({LogProperties.class})
@ConditionalOnProperty(value = {"ozo.log.enabled"}, matchIfMissing = true)
@ImportAutoConfiguration(value = Ip2regionConfiguration.class)
public class LogAutoConfiguration {

    @Bean
    public OperateLogAspect logAspect() {
        return new OperateLogAspect();
    }

    @Bean
    public OperateLogListener operateLogListener(SysOperateLogFeignClient sysOperateLogFeignClient) {
        return new OperateLogListener(sysOperateLogFeignClient);
    }

}
